package com.atguigu.daijia.map.client.fallback;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.map.client.WxPayFeignClient;
import com.atguigu.daijia.model.form.payment.PaymentInfoForm;
import com.atguigu.daijia.model.vo.payment.WxPrepayVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @create: 2024/10/2
 * @author: gyhe10
 * @description: WxPayFeignClient 接口的降级实现工厂类
 **/
@Component
public class WxPayFeignClientFallbackFactory implements FallbackFactory<WxPayFeignClient> {
    @Override
    public WxPayFeignClient create(Throwable cause) {
        return new WxPayFeignClient() {
            @Override
            public Result<WxPrepayVo> createWxPayment(PaymentInfoForm paymentInfoForm) {
                if (cause instanceof GuiguException) {
                    return Result.build(null, ((GuiguException) cause).getCode(), cause.getMessage());
                } else {
                    return Result.build(null, ResultCodeEnum.FEIGN_FAIL);
                }
            }

            @Override
            public Result<Boolean> queryPayStatus(String orderNo) {
                if (cause instanceof GuiguException) {
                    return Result.build(null, ((GuiguException) cause).getCode(), cause.getMessage());
                } else {
                    return Result.build(null, ResultCodeEnum.FEIGN_FAIL);
                }
            }
        };
    }
}
